# encoding: utf-8
# @File   : theme.py
# @Author : 乖孩子
# @Date   : 2025/07/24 16:31:13
import tkinter as tk
from tkinter import ttk


class Theme:
    # 颜色方案
    COLORS = {
        "primary": "#1E3A8A",  # 深蓝主色
        "secondary": "#3B82F6",  # 亮蓝辅助色
        "accent": "#F97316",  # 橙色强调色
        "success": "#10B981",  # 绿色成功
        "danger": "#EF4444",  # 红色错误
        "background": "#F8FAFC",  # 浅灰背景
        "card": "#FFFFFF",  # 卡片白色
        "text": "#1E293B",  # 文本深色
        "text_light": "#64748B",  # 文本浅色
        "border": "#DBEAFE"  # 边框色
    }

    # 字体方案
    FONTS = {
        "title": ("Segoe UI", 18, "bold"),
        "subtitle": ("Segoe UI", 14, "bold"),
        "body": ("Microsoft YaHei", 10),
        "small": ("Microsoft YaHei", 9),
        "mono": ("Consolas", 10)
    }

    @staticmethod
    def setup_theme(root):
        """初始化全局主题"""
        style = ttk.Style(root)

        # 创建自定义主题
        style.theme_create("smart_theme", parent="alt", settings={
            # 按钮样式
            "Accent.TButton": {
                "configure": {
                    "font": Theme.FONTS["body"],
                    "background": Theme.COLORS["accent"],
                    "foreground": "white",
                    "padding": (10, 5),
                    "borderwidth": 0,
                    "relief": "flat"
                },
                "map": {
                    "background": [("active", "#EA580C"), ("pressed", "#C2410C")],
                    "foreground": [("disabled", "#AAAAAA")]
                }
            },

            "TButton": {
                "configure": {
                    "font": Theme.FONTS["body"],
                    "background": Theme.COLORS["secondary"],
                    "foreground": "white",
                    "padding": (10, 5),
                    "borderwidth": 0
                },
                "map": {
                    "background": [("active", "#2563EB"), ("pressed", "#1D4ED8")],
                    "foreground": [("disabled", "#AAAAAA")]
                }
            },

            # 输入框样式
            "TEntry": {
                "configure": {
                    "font": Theme.FONTS["body"],
                    "fieldbackground": "white",
                    "borderwidth": 1,
                    "relief": "flat",
                    "padding": 5,
                    "insertwidth": 2
                },
                "map": {
                    "bordercolor": [("focus", Theme.COLORS["accent"]), ("!focus", Theme.COLORS["border"])]
                }
            },

            # 标签样式
            "TLabel": {
                "configure": {
                    "font": Theme.FONTS["body"],
                    "foreground": Theme.COLORS["text"]
                }
            },

            # 面板样式
            "TFrame": {
                "configure": {
                    "background": Theme.COLORS["background"],
                    "borderwidth": 0
                }
            },

            # 带边框的面板
            "Card.TFrame": {
                "configure": {
                    "background": Theme.COLORS["card"],
                    "borderwidth": 1,
                    "relief": "flat",
                    "bordercolor": Theme.COLORS["border"],
                    "padding": 10
                }
            },

            # 进度条样式
            "TProgressbar": {
                "configure": {
                    "background": Theme.COLORS["accent"],
                    "borderwidth": 0,
                    "troughcolor": Theme.COLORS["border"],
                    "thickness": 6
                }
            }
        })

        # 应用主题
        style.theme_use("smart_theme")